var MonthPlanAction = function (config) {
};

MonthPlanAction.prototype = {
    init: function (config) {
        this.loadevent();
        this.loadOtherEvent();
        this.actionUrl();
    },
    //公共选择商品界面
    loadevent: function () {
        //修改弹窗
        $('#addItemsBtn').click(function () {
            tipsWindown(
                '添加月度明细',
                    'url:get?' + baseUrl + 'monthplans/choosegood?t=' + new Date().getTime(),
                '980',
                '600',
                'true',
                '',
                'true',
                'text',
                '');
        });
        //窗口里的内容 ajax 加载分页
        jQuery("#windown-content .pagination a").live('click', function (e) {
            stopDefault(e);
            var DP_RUL = jQuery(this).attr("href")
            console.log('DP_RUL:', DP_RUL);
            jQuery("#windown-content").load(DP_RUL, {
                'searchGoodName': $('#searchGoodName').val(),
                't': new Date().getTime()
            });
        });
        //查询的选择
        $('#searchBtn').live('click', function () {
            var DP_RUL = '/monthplans/choosegood'
            jQuery("#windown-content").load(DP_RUL, {
                'searchGoodName': $('#searchGoodName').val(),
                'year': $('#year').val(),
                'month': $('#month').val(),
                'departmentId': $('#departmentId').val(),
                't': new Date().getTime()
            });
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $("#searchBtn").trigger("click");
            }
        });
        //转换当前this 指针
        var currentAction = this;
        console.log("currentAction:" , currentAction);
        $('#choosegoodBody a[class="btn-buy"]').live('click', function () {
            //组合相关的数据
            var commbinObj = {};
            var attributeArr = ['goodid', 'goodName', 'goodCode', 'goodSpec', 'goodUnit' , 'goodPrice'];
            for (var i = 0; i < attributeArr.length; i++) {
                var attributeName = attributeArr[i];
                //动态添加属性
                commbinObj[attributeName] = $(this).attr(attributeName);
            }
            currentAction.renderItems(commbinObj);
        });
    },
    //其他的加载项 可以由子类覆盖实现
    loadOtherEvent: function(){

    },
    //请求的url
    actionUrl: function (config) {
    },
    //渲染到页面
    renderItems: function () {
    },
    //计算金额
    calculate : function(){
    },
    //组合数据
    combineData: function () {
    },
    //提交到服务端
    doServer: function () {
    },
    //工具
    commonUtil: function () {
        return {
            stopEvent: function (e) {
                // Prevent the default browser action (W3C)
                if (e && e.preventDefault) {
                    e.preventDefault();
                    // A shortcut for stoping the browser action in IE
                }
                else {
                    window.event.returnValue = false;
                }
                return false;
            }
        }
    }
};
